﻿Imports System.Data.OleDb
Public Class ekmathisi
    Private Sub Synexeia_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Synexeia.Click
        Me.Hide()
        test.Show()
    End Sub 'telos ola ok
    Private Sub Hear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Hear.Click
        Dim speech
        speech = CreateObject("SAPI.spvoice")
        speech.Speak(Kseni_leksi.Text)
    End Sub 'telos ola ok
    Private Sub ekmathisi_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Elliniki_leksi.ReadOnly = True
        Kseni_leksi.ReadOnly = True
        kseni.Text() = arxiki.Glwssa.SelectedItem
        Me.GreekTableAdapter.Fill(Me.LexikoDataSet.greek)
        If (arxiki.Glwssa.SelectedItem = "Ισπανικά") Then
            Me.SpanishTableAdapter.Fill(Me.LexikoDataSet.spanish)
            If (arxiki.Arxarios.Checked = True) Then
                Elliniki_leksi.DataBindings.Add("Text", LexikoDataSet, "greek.easy words")
                Kseni_leksi.DataBindings.Add("Text", LexikoDataSet, "spanish.easy words")
            End If
            If (arxiki.Metrios.Checked = True) Then
                Elliniki_leksi.DataBindings.Add("Text", LexikoDataSet, "greek.medium words")
                Kseni_leksi.DataBindings.Add("Text", LexikoDataSet, "spanish.medium words")
            End If
            If (arxiki.Proxorimenos.Checked = True) Then
                Elliniki_leksi.DataBindings.Add("Text", LexikoDataSet, "greek.difficult words")
                Kseni_leksi.DataBindings.Add("Text", LexikoDataSet, "spanish.difficult words")
            End If
        End If
        If (arxiki.Glwssa.SelectedItem = "Αγγλικά") Then
            Me.EnglishTableAdapter.Fill(Me.LexikoDataSet.english)
            If (arxiki.Arxarios.Checked = True) Then

                Elliniki_leksi.DataBindings.Add("Text", LexikoDataSet, "greek.easy words")
                Kseni_leksi.DataBindings.Add("Text", LexikoDataSet, "english.easy words")

            End If
            If (arxiki.Metrios.Checked = True) Then
                Elliniki_leksi.DataBindings.Add("Text", LexikoDataSet, "greek.medium words")
                Kseni_leksi.DataBindings.Add("Text", LexikoDataSet, "english.medium words")
            End If
            If (arxiki.Proxorimenos.Checked = True) Then
                Elliniki_leksi.DataBindings.Add("Text", LexikoDataSet, "greek.difficult words")
                Kseni_leksi.DataBindings.Add("Text", LexikoDataSet, "english.difficult words")
            End If
        End If
        If (arxiki.Glwssa.SelectedItem = "Ιταλικά") Then
            Me.ItalianTableAdapter.Fill(Me.LexikoDataSet.italian)
            If (arxiki.Arxarios.Checked = True) Then
                Elliniki_leksi.DataBindings.Add("Text", LexikoDataSet, "greek.easy words")
                Kseni_leksi.DataBindings.Add("Text", LexikoDataSet, "italian.easy words")

            End If
            If (arxiki.Metrios.Checked = True) Then
                Elliniki_leksi.DataBindings.Add("Text", LexikoDataSet, "greek.medium words")
                Kseni_leksi.DataBindings.Add("Text", LexikoDataSet, "italian.medium words")
            End If
            If (arxiki.Proxorimenos.Checked = True) Then
                Elliniki_leksi.DataBindings.Add("Text", LexikoDataSet, "greek.difficult words")
                Kseni_leksi.DataBindings.Add("Text", LexikoDataSet, "italian.difficult words")
            End If
        End If
        If (arxiki.Glwssa.SelectedItem = "Γαλλικά") Then
            Me.FrenchTableAdapter.Fill(Me.LexikoDataSet.french)
            If (arxiki.Arxarios.Checked = True) Then
                Elliniki_leksi.DataBindings.Add("Text", LexikoDataSet, "greek.easy words")
                Kseni_leksi.DataBindings.Add("Text", LexikoDataSet, "french.easy words")

            End If
            If (arxiki.Metrios.Checked = True) Then
                Elliniki_leksi.DataBindings.Add("Text", LexikoDataSet, "greek.medium words")
                Kseni_leksi.DataBindings.Add("Text", LexikoDataSet, "french.medium words")
            End If
            If (arxiki.Proxorimenos.Checked = True) Then
                Elliniki_leksi.DataBindings.Add("Text", LexikoDataSet, "greek.difficult words")
                Kseni_leksi.DataBindings.Add("Text", LexikoDataSet, "french.difficult words")
            End If
        End If
    End Sub 'telos ola ok
    Private Sub Epistrofi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Epistrofi.Click
        Me.Close()
        arxiki.Show()
    End Sub 'ola ok
    Private Sub Proigoumeni_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Proigoumeni.Click
        BindingContext(LexikoDataSet, "greek").Position = BindingContext(LexikoDataSet, "greek").Position - 1
        If (arxiki.Glwssa.SelectedItem = "Ισπανικά") Then
            BindingContext(LexikoDataSet, "spanish").Position = BindingContext(LexikoDataSet, "spanish").Position - 1
        End If
        If (arxiki.Glwssa.SelectedItem = "Αγγλικά") Then
            BindingContext(LexikoDataSet, "english").Position = BindingContext(LexikoDataSet, "english").Position - 1
        End If
        If (arxiki.Glwssa.SelectedItem = "Γαλλικά") Then
            BindingContext(LexikoDataSet, "french").Position = BindingContext(LexikoDataSet, "french").Position - 1
        End If
        If (arxiki.Glwssa.SelectedItem = "Ιταλικά") Then
            BindingContext(LexikoDataSet, "italian").Position = BindingContext(LexikoDataSet, "italian").Position - 1
        End If
    End Sub 'ola ok

    Private Sub Epomeni_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Epomeni.Click
        BindingContext(LexikoDataSet, "greek").Position = BindingContext(LexikoDataSet, "greek").Position + 1
        If (arxiki.Glwssa.SelectedItem = "Ισπανικά") Then
            BindingContext(LexikoDataSet, "spanish").Position = BindingContext(LexikoDataSet, "spanish").Position + 1
        End If
        If (arxiki.Glwssa.SelectedItem = "Αγγλικά") Then
            BindingContext(LexikoDataSet, "english").Position = BindingContext(LexikoDataSet, "english").Position + 1
        End If
        If (arxiki.Glwssa.SelectedItem = "Γαλλικά") Then
            BindingContext(LexikoDataSet, "french").Position = BindingContext(LexikoDataSet, "french").Position + 1
        End If
        If (arxiki.Glwssa.SelectedItem = "Ιταλικά") Then
            BindingContext(LexikoDataSet, "italian").Position = BindingContext(LexikoDataSet, "italian").Position + 1
        End If
    End Sub 'ola ok
    Private Sub Add_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Add.Click
        Elliniki_leksi.ReadOnly = False
        Kseni_leksi.ReadOnly = False
        MsgBox("Οι λέξεις που θα εισάγεται πρέπει να περιέχουν πεζούς χαρακτήρες για να γίνουν δεκτές")
        BindingContext(LexikoDataSet, "greek").AddNew()
        If (arxiki.Glwssa.SelectedItem = "Ισπανικά") Then
            BindingContext(LexikoDataSet, "spanish").AddNew()
        End If
        If (arxiki.Glwssa.SelectedItem = "Ιταλικά") Then
            BindingContext(LexikoDataSet, "italian").AddNew()
        End If
        If (arxiki.Glwssa.SelectedItem = "Γαλλικά") Then
            BindingContext(LexikoDataSet, "french").AddNew()
        End If
        If (arxiki.Glwssa.SelectedItem = "Αγγλικά") Then
            BindingContext(LexikoDataSet, "english").AddNew()
        End If
    End Sub 'ola ok
    Private Sub Delete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Delete.Click
        Elliniki_leksi.ReadOnly = True
        Kseni_leksi.ReadOnly = True
        BindingContext(LexikoDataSet, "greek").RemoveAt(BindingContext(LexikoDataSet, "greek").Position)
        If (arxiki.Glwssa.SelectedItem = "Ισπανικά") Then
            BindingContext(LexikoDataSet, "spanish").RemoveAt(BindingContext(LexikoDataSet, "spanish").Position)
        End If
        If (arxiki.Glwssa.SelectedItem = "Αγγλικά") Then
            BindingContext(LexikoDataSet, "english").RemoveAt(BindingContext(LexikoDataSet, "english").Position)
        End If
        If (arxiki.Glwssa.SelectedItem = "Γαλλικά") Then
            BindingContext(LexikoDataSet, "french").RemoveAt(BindingContext(LexikoDataSet, "french").Position)
        End If
        If (arxiki.Glwssa.SelectedItem = "Ιταλικά") Then
            BindingContext(LexikoDataSet, "italian").RemoveAt(BindingContext(LexikoDataSet, "italian").Position)
        End If
    End Sub 'ολα οκ
    Private Function EllinikiTextBox_Validating() As Boolean
        Dim greek As String
        Dim j As Integer
        j = 0
        Dim result1 As Boolean
        result1 = True
        Dim gChar As Char
        greek = Elliniki_leksi.Text
        While j < greek.Length - 1 And result1.Equals(True)
            gChar = greek.Chars(j)
            If Not Char.IsLower(gChar) Or IsNumeric(gChar) Or Not (gChar Like ("[α-ω]")) Then
                result1 = False
            End If
            j = j + 1
        End While
        Return result1
    End Function
    Private Function kseniTextBox_Validating() As Boolean
        Dim tString As String
        Dim i As Integer
        i = 0
        Dim result As Boolean
        result = True
        Dim tChar As Char
        tString = Kseni_leksi.Text
        While i < tString.Length - 1 And result.Equals(True)
            tChar = tString.Chars(i)
            If Not Char.IsLower(tChar) Or IsNumeric(tChar) Or Not (tChar Like ("[a-z]")) Then
                result = False
            End If
            i = i + 1
        End While
        Return result
    End Function
    Private Function keno_Validating() As Boolean
        Dim result3 As Boolean
        result3 = True
        If Kseni_leksi.Text = Nothing Or Elliniki_leksi.Text = Nothing Then
            result3 = False
        End If
        Return result3
    End Function
    Private Function SaveChanges() As Boolean
        Dim tf As Boolean
        If ((Me.EllinikiTextBox_Validating = False) Or (Me.kseniTextBox_Validating() = False) Or keno_Validating() = False) Then
            tf = False
            MsgBox("Εισαγωγή μη επιτρεπτού χαρακτήρα!")
        ElseIf ValidateData() Then
            Me.TableAdapterManager.UpdateAll(Me.LexikoDataSet)
            tf = True
        End If
        Return tf
    End Function
    Private Function ValidateData() As Boolean
        If Me.Validate() Then
            Try
                GreekBindingSource.EndEdit()
                Me.GreekTableAdapter.Update(Me.LexikoDataSet.greek)
                Return True
            Catch ex As Exception
                If MessageBox.Show( _
                  "Πληκτρολογήθηκαν μη αποδεκτά δεδομένα.Aκυρώστε τις αλλαγές;", _
                  "Greek", MessageBoxButtons.YesNo, _
                  MessageBoxIcon.Error) = DialogResult.Yes Then
                    GreekBindingSource.CancelEdit()
                End If
                Return False
            End Try
        End If
        Return False
    End Function
    Private Sub DataValidation_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
        If ValidateData() Then
            If Me.LexikoDataSet.greek.GetChanges IsNot Nothing _
              Or Me.LexikoDataSet.english.GetChanges IsNot Nothing _
             Or Me.LexikoDataSet.spanish.GetChanges IsNot Nothing Or _
              Me.LexikoDataSet.french.GetChanges IsNot Nothing Or _
                Me.LexikoDataSet.italian.GetChanges IsNot Nothing Then
                Dim response As Integer = MessageBox.Show("Θέλετε να αποθηκεύσετε τις αλλαγές σας;", "'Εχουν γίνει αλλαγές", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning)
                If response = DialogResult.Yes Then
                    If SaveChanges() Then
                        MsgBox("Οι επιλογές σας έχουν εισαχθεί επιτυχώς στο σύστημα!")
                    Else
                        MsgBox("Οι επιλογές σας δεν μπορούν να γίνουν δεκτές!")
                    End If
                End If
            End If
        End If
    End Sub

    Private Sub Save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Save.Click
        Elliniki_leksi.ReadOnly = True
        Kseni_leksi.ReadOnly = True
        If SaveChanges() Then
            MsgBox("Οι επιλογές σας έχουν εισαχθεί επιτυχώς στο σύστημα!")
        Else
            MsgBox("Οι επιλογές σας δεν μπορούν να γίνουν δεκτές!")
        End If
    End Sub
End Class

